from .trigger import AlertTrigger
from .enter import EnterTrigger
from .leave import LeaveTrigger
from .pa2s import PassTrigger
from .stay import StayTrigger
from .count import CountTrigger


__all__ = [
    'AlertTrigger',
    'parse_trigger'
]

def parse_trigger(alert_config) -> AlertTrigger:
    condition = alert_config['condition']
    event, object, args = alert_config['event'], alert_config['object'], alert_config['args'] or []

    if condition == '出现':
        return EnterTrigger(event, object)
    elif condition == '离开':
        return LeaveTrigger(event, object)
    elif condition == '滞留':
        return StayTrigger(event, object, *args)
    elif condition.endswith('经过'):
        return PassTrigger(event, object, condition)
    elif '等于' in condition \
        or '小于' in condition \
        or '大于' in condition :
        return CountTrigger(event, object, condition, *args)
    raise RuntimeError(f'未知报警条件：{condition}')
